﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test1
{
    public partial class Form03 : Form
    {
        public Form03()
        {
            InitializeComponent();
        }
        #region 09-04
        private void button1_Click(object sender, EventArgs e)
        {
            string strPop = "您选择的权限如下：";
            foreach (Control ctl in this.Controls)
            {
                if (ctl.GetType().Name == "CheckBox")
                {
                    CheckBox cbox = (CheckBox)ctl;
                    if (cbox.Checked)
                        strPop += "\n" + cbox.Text;
                }
            }
            MessageBox.Show(strPop);
        }
        #endregion

        #region 09-05
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            label2.Text = "您选择的的职位为：" + comboBox1.SelectedItem;
        }
        #endregion

        #region 09-06
        private void 全部展开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            treeView1.ExpandAll();
        }

        private void 全部折叠ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            treeView1.CollapseAll();
        }
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            label3.Text = "您选择的部门：" + e.Node.Text;
        }
        #endregion


        private void Form3_Load(object sender, EventArgs e)
        {
            #region 09-05
            string[] str0905 = { "总经理", "副总经理", "人事部经理", "财务部经理", "部门经理", "普通员工" };
            comboBox1.DataSource = str0905;
            comboBox1.SelectedIndex = 0;
            #endregion

            #region 09-06
            treeView1.ContextMenuStrip = contextMenuStrip1;
            TreeNode TopNode = treeView1.Nodes.Add("公司");
            TreeNode node1 = new TreeNode("人事部");
            TreeNode node2 = new TreeNode("财务部");
            TreeNode node3 = new TreeNode("基础部");
            TreeNode node4 = new TreeNode("软件开发部");
            TopNode.Nodes.Add(node1);
            TopNode.Nodes.Add(node2);
            TopNode.Nodes.Add(node3);
            TopNode.Nodes.Add(node4);

            TreeNode chilenode1 = new TreeNode("C#部门");
            TreeNode chilenode2 = new TreeNode("ASP.NET部门");
            TreeNode chilenode3 = new TreeNode("Java部门");
            TreeNode chilenode4 = new TreeNode("VB部门");
            TreeNode chilenode5 = new TreeNode("C语言部门");
            TreeNode chilenode6 = new TreeNode("PHP部门");
            node4.Nodes.Add(chilenode1);
            node4.Nodes.Add(chilenode2);
            node4.Nodes.Add(chilenode3);
            node4.Nodes.Add(chilenode4);
            node4.Nodes.Add(chilenode5);
            node4.Nodes.Add(chilenode6);

            imageList1.Images.Add(Image.FromFile("1.png"));
            imageList1.Images.Add(Image.FromFile("2.png"));
            treeView1.ImageList = imageList1;
            imageList1.ImageSize = new Size(16, 16);
            treeView1.ImageIndex = 0;
            treeView1.SelectedImageIndex = 1;
            #endregion
        }
        #region 09-07
        private void button3_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Random rand = new Random();//Random 生成随机数的类
            label4.Text = rand.Next(1, 33).ToString("00");
            label5.Text = rand.Next(1, 33).ToString("00");
            label6.Text = rand.Next(1, 33).ToString("00");
            label7.Text = rand.Next(1, 33).ToString("00");
            label8.Text = rand.Next(1, 33).ToString("00");
            label9.Text = rand.Next(1, 33).ToString("00");
            label10.Text = rand.Next(1, 16).ToString("00");
        }
        #endregion
    }
}
